package com.hxs.hxsserver.controller.relay;

import com.hxs.hxsserver.controller.BaseController;
import com.hxs.hxsserver.domain.dto.JsonResult;

import com.hxs.hxsserver.domain.dto.device.IdsDTO;
import com.hxs.hxsserver.domain.dto.device.QueryRelayModeListDTO;
import com.hxs.hxsserver.domain.dto.device.RelayModeInsertReqDTO;
import com.hxs.hxsserver.domain.dto.device.RelayModeInsertReturnDTO;
import com.hxs.hxsserver.service.RelayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author liuchuan
 * @create 2024/11/19
 */
@Slf4j
@RestController
@Api(value = "继电器模式管理")
@RequestMapping("relayMode")
public class RelayModeController extends BaseController {

    @Resource
    RelayService relayService;

    @PostMapping("/insertRelayMode")
    @ApiOperation(value = "新增继电器计划")
    public JsonResult<Boolean> insertRelayMode(@RequestBody @Validated RelayModeInsertReqDTO relayDTO){
        return JsonResult.success(relayService.insertRelayMode(relayDTO,getUser()));
    }

    @GetMapping("/getRelayModeListByMode")
    @ApiOperation(value = "根据模式获取继电器计划")
    public JsonResult<List<RelayModeInsertReturnDTO>> getRelayModeListByMode(QueryRelayModeListDTO queryRelayModeListDTO){
        return JsonResult.success(relayService.getRelayModeListByMode(queryRelayModeListDTO));
    }

    @PostMapping("/updateRelayModeById")
    @ApiOperation(value = "根据id修改继电器计划")
    public JsonResult<Boolean> updateRelayModeById(@RequestBody @Validated RelayModeInsertReturnDTO relayDTO){
        return JsonResult.success(relayService.updateRelayModeById(relayDTO,getUser()));
    }

    @PostMapping("/deleteRelayModeByIds")
    @ApiOperation(value = "批量删除，主键id逗号隔开")
    public JsonResult<Boolean> deleteRelayModeById(@RequestBody IdsDTO ids){
        return JsonResult.success(relayService.deleteRelayModeByIds(ids.getIds()));
    }
}
